﻿#ifndef SCENENODE_HEADER
#define SCENENODE_HEADER

#include <vector>
#include <list>
#include "../Entities/AbstractClasses/GameEntity.h"

class SceneNode {
public:
	SceneNode(SceneNode *);				//Constructor, parent node as parameter
	~SceneNode();						//Destructor

	void addEntity(GameEntity *);		//Add the entity to the scene node
	void removeEntity(GameEntity *);	//Remove the entity from the scene node
	GameEntity * getEntity(const std::string&);//Search for an entity by its name
	void removeAllEntities();			//Remove all entities (no destruction)
	void deleteAllEntities();			//Delete all entities
	std::list<SceneNode *> getChildren();//Get all the children
	std::list<GameEntity *> getEntities();//Get all the entities

	SceneNode * createChildSceneNode();	//Create and return a child of the scene node
	void removeChildSceneNode(SceneNode *);//Remove a child node
	SceneNode * getParentSceneNode() const;//Get the parent scene node
	void deleteAllChildrenSceneNodes();	//Delete all children scene nodes (and remove entities)
	void deleteAllChilderAndEntitiesSceneNode();//Delete all children scene nodes and entities

	ORIENTATION getOrientation() const;//Get the (local) orientation of the node
	void setOrientation(ORIENTATION);//Set the (local) orientation of the node
	POINT3D getPosition() const;//Get the (local) position of the node
	void setPosition(POINT3D);//Set the (local) position of the node
	void updateSceneNode(); // Update the scene from the current node
	void checkNodesAlive();

	void renderSceneNode(); // Render the scene from the current node
	void enterRenderingSceneNode(); // Move into the node (push context, apply loca
	void exitRenderingSceneNode(); // Move out of the node (pop context)
	bool write(std::ostream&) const; // Write object to stream
	void read(std::istream&); // Read object from stream

	int getChildsToCreate();
	void setChildsToCreate(int);

	void destroy();
	bool toDestroy();

private:
	std::list<SceneNode *> children;
	SceneNode * _parentSceneNode; // The parent node (NULL if root)
	std::list<GameEntity *> entities;
	ORIENTATION orientation;
	POINT3D position;
	int _childsToCreate;
	bool _destroy;
};

#endif